User Guide > Getting Started > Tutorial: Create Your First Project |
In this step-by-step tutorial we’ll build a complete application to recognize text in an image and output all the individual words and their locations to the terminal.
Before running this tutorial a license for OCRXpress for Java should already be installed.
If you have run the setup script in the install folder then you should have an evaluation license already. If not, then see License Manager to install a license. |
For this tutorial, we are using the Eclipse IDE.
Copy Code
|
|
---|---|
import com.accusoft.ocrxpress.Document; import com.accusoft.ocrxpress.OcrxException; import com.accusoft.ocrxpress.OcrXpress; import com.accusoft.ocrxpress.RecognitionParameters; import com.accusoft.ocrxpress.Language; import com.accusoft.ocrxpress.Word; import com.accusoft.ocrxpress.Rectangle; import java.awt.image.*; import javax.imageio.*; import java.io.*; |
Copy Code
|
|
---|---|
System.out.println("\n....................... Begin Tutorial .......................\n"); String inputImagePath = "/path/to/install/location/Accusoft/OCRXpressJava3-64/samples/images/text.bmp"; //Read in the image from inputImagePath BufferedImage bufferedImg = null; try { bufferedImg = ImageIO.read(new File(inputImagePath)); } catch (IOException e) { System.out.println("Failed to open the image file: "); e.printStackTrace(); return; } |
Copy Code
|
|
---|---|
OcrXpress.setDataPrefixPath("/path/to/install/location/Accusoft/OCRXpressJava3-64/bin/");
|
Copy Code
|
|
---|---|
RecognitionParameters params = new RecognitionParameters(); OcrXpress ocrEngine = new OcrXpress(); Document recognitionResults; |
Copy Code
|
|
---|---|
try { params.setLanguage(Language.ENGLISH); System.out.println("Performing ocr on the image file."); recognitionResults = ocrEngine.recognizeToMemory(params, bufferedImg); |
Copy Code
|
|
---|---|
for (Word wd : recognitionResults.getWords()) { System.out.println(wd.toString() + " at (" + wd.getArea().getLeft() + "," + wd.getArea().getTop() + ")"); } } //end of try |
Copy Code
|
|
---|---|
catch (OcrxException ex){ System.out.println("Recognition failure: " + ex.getMessage()); } System.out.println("Finished tutorial."); |